< previous page page_58 next page >

Page 58
0058-01.jpg
Figure 2.1
The API Viewer.
Declaring the Routine
Because API routines are not part of Visual Basic, you must use a Declare statement to tell Visual Basic where to find them. The syntax for a Declare statement is:
Declare Sub name Lib "lib" [Alias "alias"] (arguments)
Declare Function name Lib "lib" [Alias "alias"] (arguments) As type
Definitions for terms used in the statement are as follows:
name. The name by which you want to call the function in your program. This is useful if the name as it appears in the library is a reserved word in Visual Basic (such as Open) or if it begins with an underscore (Visual Basic does not allow function names to begin with an underscore). You can also use an alias to make programming easier. For example, you might make SizeBitmap the alias for the SetBitmapDimensionEx function to save some typing.
lib. The location of the library. For system libraries, this is the name of the library (such as gdi32 or kernel32). The API functions are all in system libraries. For non-system libraries, lib is the path to the library, such as C:\Winstuff\Bitmaps.dll.
alias. The name by which the subroutine or function is defined in the library.

 
< previous page page_58 next page >